<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('固定资产-支付管理') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('申请标题')" prop="actTitle">
        <el-input
          v-model="queryParams.actTitle"
          :placeholder="$t('申请标题')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('合同名称')" prop="contractName">
        <el-input
          v-model="queryParams.contractName"
          :placeholder="$t('合同名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('申请人')" prop="userName">
        <el-input
          v-model="queryParams.userName"
          :placeholder="$t('申请人')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fixedAssets:payment:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          v-hasPermi="['fixedAssets:payment:export']"-->
      <!--          type="warning"-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="exportHandle"-->
      <!--        >{{ $t('导出') }}</el-button>-->
      <!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="dealFixedAssetsPaymentList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="center" prop="actTitle">
        <template slot-scope="scope">
          <el-link class="link-a" type="primary" @click="updateHandle(scope.row)">{{ scope.row.actTitle }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请人')" align="center" prop="userName" />
      <el-table-column :label="$t('合同名称')" align="center" prop="contractName" />
      <!--      <el-table-column :label="$t('支付主体')" align="center" prop="investMain" />-->
      <el-table-column :label="$t('申请支付金额') + $t('金额单位')" align="center" prop="requestPaymentAmount">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.requestPaymentAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('支付条件满足情况')" align="center" prop="meetPaymentTerms" />
      <el-table-column :label="$t('审批状态')" align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.actStatus === 'W'"
            v-hasPermi="['fixedAssets:payment:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updatePayTimeBtn(scope.row)"
          >{{ $t('维护支付结果') }}</el-button>
          <!-- 启动流程，终止流程，修改，删除 四个按钮 -->
          <ListBtn :bus-data="scope.row" has-permi="fixedAssets:payment" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改固定资产-支付管理对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealFixedAssetsPaymentForm ref="dealFixedAssetsPaymentForm" />
    </el-dialog>

    <!-- 维护付款结果 -->
    <el-dialog :title="$t('维护支付结果')" :visible.sync="paymentResultOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <MaintainPaymentInfo ref="MaintainPaymentInfo" :act-title="MaintainPaymentInfoTitle" />
    </el-dialog>

  </div>
</template>

<script>
import { listDealFixedAssetsPayment, delDealFixedAssetsPayment, exportDealFixedAssetsPayment } from '@/api/deal/fixedAssets/dealFixedAssetsPayment'
import dealFixedAssetsPaymentForm from './dealFixedAssetsPaymentForm.vue'
import MaintainPaymentInfo from './maintainPaymentInfo.vue'
import { updatePayTime } from '@/api/deal/payment/dealPayment'
export default {
  components: {
    dealFixedAssetsPaymentForm,
    MaintainPaymentInfo
  },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 固定资产-支付管理表格数据
          dealFixedAssetsPaymentList: [],
          // 弹出层标题
          title: '固定资产-支付管理',
          MaintainPaymentInfoTitle: '',
          // 是否显示弹出层
          formOpen: false,
          paymentResultOpen: false,
          // 查询参数
          queryParams: {
              actTitle: undefined,
              contractName: undefined,
              userName: undefined,
              dealId: this.$route.query.id,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
  },
  methods: {
    /** 查询固定资产-支付管理列表 */
    getList() {
        this.loading = true
        listDealFixedAssetsPayment(this.queryParams).then(response => {
            this.dealFixedAssetsPaymentList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: undefined,
            actTitle: undefined,
            userId: undefined,
            company: undefined,
            department: undefined,
            contractId: undefined,
            investMain: undefined,
            requestPaymentAmount: undefined,
            meetPaymentTerms: undefined,
            abstracts: undefined,
            actId: undefined,
            actStatus: '0',
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealFixedAssetsPaymentForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealFixedAssetsPaymentForm.init(row)
        })
    },
    // 付款维护 : 按钮获取数据
    updatePayTimeBtn(row) {
      this.paymentResultOpen = true
      this.MaintainPaymentInfoTitle = row.contractName + '-维护付款结果'
      this.$nextTick(() => {
        this.$refs.MaintainPaymentInfo.init(row)
      })
    },
    // 付款时间维护 : 保存到后台
    updatePaySuccess(data) {
      updatePayTime(data).then(respones => {
        if (respones.code === 200) {
          this.msgSuccess('操作成功!')
          this.getList()
          this.MaintainPaymentInforLoading = false
        } else {
          this.msgSuccess(this.$t('维护失败'))
        }
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        return delDealFixedAssetsPayment(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(() => {
          this.loading = false
      })
    },
    /** 导出按钮操作 */
    exportHandle() {
      const queryParams = this.queryParams
      this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(() => {
        return exportDealFixedAssetsPayment(queryParams)
      }).then(response => {
        this.download(response.msg)
      }).catch(() => {
      })
    }
  }
}
</script>
